package io.xxx.omni.osc.config

import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.scheduling.concurrent.CustomizableThreadFactory
import java.util.concurrent.ArrayBlockingQueue
import java.util.concurrent.ThreadPoolExecutor
import java.util.concurrent.TimeUnit

@Configuration
class ThreadPoolConfig {

    @Bean
    fun executor(): ThreadPoolExecutor {
        val processor = Runtime.getRuntime().availableProcessors()
        return ThreadPoolExecutor(
            processor, processor * 2,
            120L, TimeUnit.SECONDS,
            ArrayBlockingQueue(500),
            CustomizableThreadFactory(),
            ThreadPoolExecutor.CallerRunsPolicy()
        )
    }
}